layui.use(['layer', 'form', 'admin', 'laydate', 'HttpRequest', 'xmSelect'], function () {
    var $ = layui.jquery;
    var HttpRequest = layui.HttpRequest;
    var form = layui.form;
    var admin = layui.admin;
    var laydate = layui.laydate;

    laydate.render({
        elem: '#birthday'
    });

    var orgId = Feng.getUrlParam('orgId');
    var kingresult = new HttpRequest(Feng.ctxPath+'/student/kindergarten?orgId='+orgId,'get');
    var result = kingresult.start();
    if (result.data === null){
        result.data ="当前无数据";
    }
    var kingobj = {'ownKindergarten':result.data}
    form.val('teacherForm', kingobj);


    form.verify({
        account:[
            /^\w{6,18}$/
            ,'用户名不能有特殊字符.长度6~18位'
        ]
    });

    /*new HttpRequest(Feng.ctxPath + "/kindergarten/tree", 'get', function (data) {
        console.info(data);
        organizationXmSel = xmSelect.render({
            el: '#organization',
            data: data.data,
            model: {label: {type: 'text'}},
            radio: true,
            layVerify: 'required',
            clickClose: true,
            tree: {
                show: true,
                indent: 15,
                strict: false,
                expandedKeys: true
            }
        });
    }).start();*/



    form.on('submit(btnSubmit)', function (data) {
        data.field['orgId'] = orgId;
        // data.field.grantRoleIdList = roleXmSel.getValue('value');
        var request = new HttpRequest(Feng.ctxPath + "/teacher/add", 'post', function (data) {
            Feng.success("添加成功！");

            //传给上个页面，刷新table用
            admin.putTempData('formOk', true);

            //关掉对话框
            admin.closeThisDialog();

        }, function (data) {
            Feng.error("添加失败！" + data.message)
        });
        request.set(data.field);
        request.start(true);

        //添加 return false 可成功跳转页面
        return false;
    });
});